﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace diploma.core.data.objects
{
    public class Problem : DataObject
    {
        private string description;
        private string solving;
        private string answer;
        private long themeId;

        public Problem(long _id, string _title, string _description, string _solving, string _answer, long _themeId)
            : base(_id, _title)
        {
            description = _description;
            solving = _solving;
            answer = _answer;
            themeId = _themeId;
        }

        public long ThemeId
        {
            get
            {
                return themeId;
            }
        }

        public string Title
        {
            get
            {
                return textField;
            }
        }

        public string Description
        {
            get
            {
                return description;
            }
        }

        public string Solving
        {
            get
            {
                return solving;
            }
        }

        public string Answer
        {
            get
            {
                return answer;
            }
        }

        public override DataObjectTypes Type
        {
            get
            {
                return DataObjectTypes.Problem;
            }
        }

        public void SetTitle(string _value, bool _innerDataSourceChanges)
        {
            SetTextField(_value, _innerDataSourceChanges);
        }

        public void SetTitle(string _value)
        {
            SetTextField(_value);
        }

        public void SetDescription(string _value, bool _innerDataSourceChanges)
        {
            description = _value;
            if (!_innerDataSourceChanges)
            {
                DataRouter.Instance.Act(DataActions.update, this.Type, this);
            }
        }
        public void SetDescription(string _value)
        {
            description = _value;
            DataRouter.Instance.Act(DataActions.update, this.Type, this);
        }
        public void SetSolving(string _value, bool _innerDataSourceChanges)
        {
            solving = _value;
            if (!_innerDataSourceChanges)
            {
                DataRouter.Instance.Act(DataActions.update, this.Type, this);
            }
        }
        public void SetSolving(string _value)
        {
            solving = _value;
            DataRouter.Instance.Act(DataActions.update, this.Type, this);
        }
        public void SetAnswer(string _value, bool _innerDataSourceChanges)
        {
            answer = _value;
            if (!_innerDataSourceChanges)
            {
                DataRouter.Instance.Act(DataActions.update, this.Type, this);
            }
        }
        public void SetAnswer(string _value)
        {
            answer = _value;
            DataRouter.Instance.Act(DataActions.update, this.Type, this);
        }

        public void SetTheme(long _value)
        {
            themeId = _value;
            DataRouter.Instance.Act(DataActions.update, this.Type, this);
        }


        #region ISerializable Members

        public override void FromStream(System.IO.Stream _stream)
        {
            base.FromStream(_stream);
            description = ByteSerialization.StringFromBytes(_stream);
            solving = ByteSerialization.StringFromBytes(_stream);
            answer = ByteSerialization.StringFromBytes(_stream);
        }

        public override void ToStream(System.IO.Stream _stream)
        {
            base.ToStream(_stream);
            ByteSerialization.StringToBytes(_stream, description);
            ByteSerialization.StringToBytes(_stream, solving);
            ByteSerialization.StringToBytes(_stream, answer);
        }

        #endregion


    }
}
